package com.juc.callable.callable4;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Test {

	/**
	 * 
	 *   boolean cancel(boolean mayInterruptIfRunning);
	 *   参数mayInterruptIfRunning的作用是如果线程正在执行
	 *   则是否中断正在运行的线程 在代码中需要使用
	 *   if(Thread.currentThread().isInterrupted())进行配合
	 *   
	 *   isCancelled()返回值代表发送取消任务的任务的命令是否成功完成
	 *    
	 * @throws InterruptedException
	 * @throws ExecutionException
	 */
	public static void main(String[] args) throws InterruptedException, ExecutionException {
		MyCallable myCallable =new MyCallable();
		ExecutorService executorService = new ThreadPoolExecutor(50, Integer.MAX_VALUE, 5, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>());
		Future<String> future = executorService.submit(myCallable);
		System.out.println(future.get());
		System.out.println(future.cancel(true) + "    " + future.isCancelled());
	}
}
